package com.bst.web.base;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.bst.base.domain.BaseReportParamFilter;
import com.bst.base.service.IBaseReportParamFilterService;
import com.bst.common.utils.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import com.bst.common.enums.BusinessType;
import com.bst.base.domain.BaseReportParam;
import com.bst.base.service.IBaseReportParamService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 报表参数管理Controller
 * 
 * @author laoliu
 * @date 2024-10-30
 */
@Controller
@RequestMapping("/base/report/param")
public class BaseReportParamController extends BaseController
{
    private String prefix = "base/report/param";

    @Autowired
    private IBaseReportParamService baseReportParamService;
    @Autowired
    private IBaseReportParamFilterService baseReportParamFilterService;

    @GetMapping()
    public String param()
    {
        return prefix + "/param";
    }

    @GetMapping("/template1/{idReportParam}")
    public String template1(@PathVariable("idReportParam") Long idReportParam,ModelMap mmap)
    {
        BaseReportParam reportParam = baseReportParamService.selectBaseReportParamByIdReportParam(idReportParam);
        mmap.put("reportParam",reportParam);
        mmap.put("dayBegin", DateUtil.FORMAT_YYYY_MM_DD.format(DateUtil.calculate(new Date(), Calendar.DAY_OF_MONTH,-10)));
        mmap.put("dayEnd", DateUtil.FORMAT_YYYY_MM_DD.format(new Date()));
        return "base/report/template/template_1";
    }

    /**
     * 查询报表参数管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseReportParam baseReportParam)
    {
        startPage();
        List<BaseReportParam> list = baseReportParamService.selectBaseReportParamList(baseReportParam);
        return getDataTable(list);
    }

    /**
     * 导出报表参数管理列表
     */
    @Log(title = "报表参数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseReportParam baseReportParam)
    {
        List<BaseReportParam> list = baseReportParamService.selectBaseReportParamList(baseReportParam);
        ExcelUtil<BaseReportParam> util = new ExcelUtil<BaseReportParam>(BaseReportParam.class);
        return util.exportExcel(list, "报表参数管理数据");
    }

    /**
     * 新增报表参数管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报表参数管理
     */
    @Log(title = "报表参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseReportParam baseReportParam)
    {
        return toAjax(baseReportParamService.insertBaseReportParam(baseReportParam));
    }

    /**
     * 修改报表参数管理
     */
    @GetMapping("/edit/{idReportParam}")
    public String edit(@PathVariable("idReportParam") Long idReportParam, ModelMap mmap)
    {
        BaseReportParam baseReportParam = baseReportParamService.selectBaseReportParamByIdReportParam(idReportParam);
        mmap.put("baseReportParam", baseReportParam);
        return prefix + "/edit";
    }

    /**
     * 修改保存报表参数管理
     */
    @Log(title = "报表参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseReportParam baseReportParam)
    {
        return toAjax(baseReportParamService.updateBaseReportParam(baseReportParam));
    }

    /**
     * 删除报表参数管理
     */
    @Log(title = "报表参数管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseReportParamService.deleteBaseReportParamByIdReportParams(ids));
    }
}
